package com.gz.controller;

import com.gz.common.APPService;
import com.gz.common.model.MobileApp;
import com.gz.utils.Response;
import com.gz.utils.StringUtil;
import com.jfinal.core.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * APP接口
 */
public class APPController extends Controller {

    //检查版本
    public void checkVersion() {
        String platform = getPara("platform");
        if (StringUtil.isEmpty(platform) ||
                !(platform.toLowerCase().trim().equals("android") || platform.toLowerCase().trim().equals("ios"))) {
            renderJson(Response.responseJson(201, "请输入平台"));
            return;
        }
        MobileApp mobileApp = APPService.getService().getVersionByPlatForm(platform);
        Map<String, String> result = new HashMap<>();
        result.put("version", mobileApp.getVersion());
        result.put("fileUrl", mobileApp.getFileUrl());
        result.put("platform", mobileApp.getPlatform());
        renderJson(Response.responseJson(200, "查询成功", result));
        return;
    }
}
